package com.example.design.shejimoshi.structure.compose.组合模式链式任务;

import java.util.ArrayList;
import java.util.List;

/**
 * CompositeTask 类，实现了 Task 接口，表示可以包含子任务的任务
 */
public class CompositeTask implements Task {
    private String name;  
    private List<Task> subTasks = new ArrayList<>();
  
    public CompositeTask(String name) {  
        this.name = name;  
    }  
  
    @Override  
    public void execute() {  
        System.out.println("Executing composite task: " + name);  
        for (Task task : subTasks) {  
            task.execute();  
        }  
    }  
  
    @Override  
    public void add(Task task) {  
        subTasks.add(task);  
    }  
  
    @Override  
    public void remove(Task task) {  
        subTasks.remove(task);  
    }  
  
    @Override  
    public boolean isLeaf() {  
        return false;  
    }  
}  